package org.example.controller;

import com.github.pagehelper.PageInfo;
import org.example.entity.Consultant;
import org.example.service.ConsultantService;
import org.example.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ConsultantController
 * @Description TODO
 * @Author yuezhijie
 * @Date 2025年08月13日 11:32
 * @Version 1.0
 */
@RestController
@RequestMapping("consultant")
public class ConsultantController {
    @Autowired
    private ConsultantService consultantService;

//    //    多表分页查询
    @GetMapping("fenye")
    public R selectConsultantAndLevel(Consultant consultant ,
                                      @RequestParam(required = false ,defaultValue = "1") int pageNum,
                                      @RequestParam(required = false,defaultValue = "5") int pageSize) {
        PageInfo<Consultant> consultantPageInfo = consultantService.selectConsultantAndLevel(consultant,pageNum,pageSize);
        return R.ok(consultantPageInfo);
    }

//    根据id级联查询
    @GetMapping("{id}")
    public R selectConsultantById(@PathVariable("id") int id) {
        Consultant consultant = consultantService.selectConsultantById(id);
        return R.ok(consultant);
    }
//    根据id查询价格
@GetMapping("/{ids}/price")
    public  R selectpriceById(@PathVariable("ids") int id) {
    List<Consultant> consultants = consultantService.selectpriceById(id);
    return R.ok(consultants);
    }

    //根据name模糊查询
    @GetMapping("name")
    public R selectConsultantByName(Consultant consultant,
                                    @RequestParam(required = false ,defaultValue = "1") int pageNum,
                                    @RequestParam(required = false,defaultValue = "3") int pageSize  ) {
        PageInfo<Consultant> consultantPageInfo = consultantService.selectConsultantByName(consultant, pageNum, pageSize);
        return R.ok(consultantPageInfo);
    }

//根据id查询咨询师回复
    @GetMapping("/{ida}/answer")
    public R selectAnswerById(@PathVariable("ida") int id) {
        List<Consultant> consultants = consultantService.selectAnswerById(id);
        return R.ok(consultants);
    }
//    查询课程所有内容
    @GetMapping("/{idc}/cours")
    public R selectCourseById(@PathVariable("idc") int id) {
        List<Consultant> consultants = consultantService.selectCourseById(id);
        return R.ok(consultants);
    }
//   咨询预约查询
    @GetMapping("ConsultantAndLevelAndTag")
    public R getConsultantAndLevelAndTag(String level,String tag) {
        List<Consultant> consultantAndLevelAndTag = consultantService.getConsultantAndLevelAndTag(level, tag);
        return R.ok(consultantAndLevelAndTag);
    }

//    根据id查询文章所有内容
//        @GetMapping("/{ida}/artic")
//    public R selectArticleById(@PathVariable("ida")  int id) {
//        List<Consultant> consultants = consultantService.selectArticleById(id);
//        return R.ok(consultants);
//    }

    @GetMapping("/{idf}/find")
    public  R findAll(@PathVariable("idf") int id) {
        List<Consultant> all = consultantService.findAll(id);
        return R.ok(all);
    }
    @PostMapping("/selectAll")
    public R selectAll(@RequestBody Consultant consultant) {
        // 处理地址模糊查询逻辑（如果需要）
        if (consultant.getAddress() != null && !consultant.getAddress().isEmpty()) {
            // 如果前端传的是类似"广东省广州市"的字符串，可以在这里处理
            consultant.setAddress(consultant.getAddress().replace(",", ""));
        }
        List<Consultant> consultants = consultantService.selectAll(consultant);
        return R.ok(consultants);
    }
    @GetMapping("/{idst}/star")
    public R selectStar(@PathVariable("idst") int id){
        List<Consultant> consultants = consultantService.selectStar(id);
        return R.ok(consultants);
    }


    @GetMapping("/selectTag")
    public  R getConsultantsAndLevelAndTags(String levelName,String tag, String address,String gender) {
        List<Consultant> consultantsAndLevelAndTags = consultantService.getConsultantsAndLevelAndTags(levelName,tag,address,gender);
        return R.ok(consultantsAndLevelAndTags);
    }

}
